package com.huiminpay.merchant.controller;

import com.huiminpay.common.cache.util.SecurityUtil;
import com.yh.huiminpay.merchant.api.AppService;
import com.yh.huiminpay.merchant.dto.AppDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("商户应用管理。应用的增删改查")
public class AppController {

    @Reference
    private AppService appService;
    //创建应用(增加)
    @ApiOperation("商户创建应用")
    @ApiImplicitParams({@ApiImplicitParam(name = "appDTO", value = "应用信息", required = true, dataType = "AppDTO", paramType = "body")})
    @PostMapping(value = "/my/apps")
    public AppDTO insertApp(@RequestBody AppDTO appDTO){
        Long merchantId = SecurityUtil.getMerchantId();
        appDTO.setMerchantId(merchantId);
        AppDTO appDTO1=appService.createApp(appDTO);
        return appDTO1;
    }
    /**
     *  根据商户id 查询该商户下的应用列表
     * @author qawine
     * @return java.util.List<com.huiminpay.merchant.api.dto.AppDTO>
     * @date 2021/3/24 20:31
     */
    @ApiOperation("查询商户下的应用列表")
    @GetMapping(value = "/my/apps")
    public List<AppDTO> queryMyApps() {
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.queryAppByMerchant(merchantId);
    }
    /**
     *  根据appId 查询应用详情
     * @author qawine
     * @param appId
     * @return com.huiminpay.merchant.api.dto.AppDTO
     * @date 2021/3/24 20:32
     */
    @ApiOperation("根据appid获取应用的详细信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "商户应用id", required = true, dataType = "String", paramType = "path")})
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO getApp(@PathVariable String appId) {
        return appService.getAppById(appId);
    }

}
